package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.BFunctionDao;
import com.mstore.pojo.BFunction;

public class BFunctionService {

	private BFunctionDao functionDao;
	
	/**
	 * 查询所有功能
	 */
	public List<BFunction> getAllFunction() {
		List<BFunction> functions = new ArrayList<BFunction>();
		List<Object> objects = functionDao.getAllFunction();
		for (Object object : objects) {
			functions.add((BFunction)object);
		}
		return functions;
	}
	
	/**
	 * 根据id查询功能
	 */
	public BFunction getFunctionById(Long funcId) {
		Object object = functionDao.getFunctionById(funcId);
		return object!= null ? (BFunction) object : null;
	}
	
	/**
	 * 添加功能
	 */
	public void addFunction(BFunction function) {
		functionDao.addFunction(function);
	}
	
	/**
	 * 删除
	 */
	public void delFunction(BFunction function) {
		functionDao.delete(function);
	}
	
	/**
	 * 修改
	 */
	public void modifyFunction(BFunction function) {
		functionDao.modifyFunction(function);
	}
	
	/**
	 * 查询名字是否重复，排除自身
	 */
	public boolean verifyFunctionNameExceptSelf(String name, Long id) {
		return functionDao.getFunctionsByNameExceptSelf(name, id).isEmpty();
	}
	
	/**
	 * 查询名字是否重复
	 */
	public boolean verifyFunctionName(String name) {
		return functionDao.getFunctionsByName(name).isEmpty();
	}
	
	public BFunctionDao getFunctionDao() {
		return functionDao;
	}

	public void setFunctionDao(BFunctionDao functionDao) {
		this.functionDao = functionDao;
	}
}
